/**
* Copyright @ 2023 iAuto (Shanghai) Co., Ltd.
* All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are NOT permitted except as agreed by
* iAuto (Shanghai) Co., Ltd.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*/



import request from '@/utils/request';
import {
  IIconCreate,
  IIconEdit,
  IIconStatus,
  IIconList,
  IIconListParams,
  IIconItem,
} from '@/types/icon';
import { IPromiseError, IPromiseListApi } from '@/types/type';
import { paginationParams } from '@/utils/soa/utils';
import base from './base';

// 管理端-新增场景图标
export async function createIcon(data: IIconCreate) {
  return await request.post<IPromiseError>(`/${base.API}/ms-soa-scene/${base.VERSION}/admin/icon`, {
    data,
  });
}

// 管理端-修改场景图标
export async function editIcon(data: IIconEdit, id: number) {
  return await request.put<IPromiseError>(`/${base.API}/ms-soa-scene/${base.VERSION}/admin/icon`, {
    data: {
      ...data,
      id,
    },
  });
}

// 管理端-删除场景图标
export async function deleteIcon(id: number) {
  return await request.delete<IPromiseError>(
    `/${base.API}/ms-soa-scene/${base.VERSION}/admin/icon`,
    {
      params: {
        id,
      },
    },
  );
}

// 管理端-场景图标列表
export async function getIconList({ current, pageSize }: IIconListParams) {
  const { data } = await request.get<IPromiseListApi<IIconList>>(
    `/${base.API}/ms-soa-scene/${base.VERSION}/admin/icon/page`,
    {
      params: {
        ...paginationParams(current, pageSize),
      },
    },
  );
  return {
    list: data?.itemSize
      ? data?.dataList.map((item: IIconItem, index: number) => ({
          ...item,
          index: index + 1 + (current - 1) * pageSize,
        }))
      : [],
    total: data?.pageCount,
  };
}

// 管理端-图标状态更改
export async function editIconStatus(status: IIconStatus, id: number) {
  return request.put(`/${base.API}/ms-soa-scene/${base.VERSION}/admin/icon/status`, {
    data: {
      status,
      id,
    },
  });
}
